# 作业：
# 1、对之前的脚本生成测试报告
import pytest,requests
from faker import Faker
import uuid,allure
uuid1 = str(uuid.uuid4()).split('-')[0]
faker = Faker(locale='zh_cn')
list_id = []
@allure.feature("用户分组")
class TestCrmeb:
    project_url = "http://60.205.190.66:8899"
    @pytest.fixture(scope='function', autouse=True)
    def setup_teardown(self):
        response = requests.post(self.project_url + "/adminapi/login",json={"account": "admin", "pwd": "920509", "imgcode": "a"})
        self.token = response.json()["data"]['token']
        yield
        print("我退出了哦~")

    @allure.story("添加分组")
    def test_usergroup(self):
        name = faker.name()
        response = requests.post(self.project_url + "/adminapi/user/user_group/save.html",json = {"group_name":str(name)},
                      headers={"Authori-Zation":"Bearer "+str(self.token)})
        assert response.json()['msg'] == "提交成功！"
        assert response.status_code ==200



        response1 = requests.get(self.project_url + "/adminapi/user/user_group/list?page=1&limit=15",headers={"Authori-Zation":"Bearer "+str(self.token)})
        assert response1.status_code == 200
        for i in response1.json()["data"]["list"]:
            if i['group_name'] == str(name):
                self.id = i["id"]

        response2 = requests.delete(self.project_url + "/adminapi/user/user_group/del/" + str(self.id),headers={"Authori-Zation":"Bearer "+str(self.token)})
        assert response2.status_code == 200
        assert response2.json()['msg'] == "删除成功!"
    def test_Customs(self):
        response1 = requests.post(self.project_url + "/adminapi/app/wechat/speechcraft",json={"cate_id":"","title":"好好好",
                                                                                                 "message":str(uuid1),"sort":0},
                                                                                                   headers={"Authori-Zation":"Bearer "+str(self.token)})
        assert response1.status_code== 200
        assert response1.json()['msg'] == '创建话术成功'

        response2 = requests.get(self.project_url + "/adminapi/app/wechat/speechcraft?page=1&limit=15&cate_id=",
                                 headers={"Authori-Zation":"Bearer "+str(self.token)})
        assert response2.status_code ==200
        for i in response2.json()['data']['list']:
            if i["message"] == str(uuid1):
                self.id = i['id']

        response3 = requests.delete(self.project_url + "/adminapi/app/wechat/speechcraft/" + str(self.id),headers={"Authori-Zation":"Bearer "+
                                                                                                                                    str(self.token)})
        assert response3.status_code ==200
        assert response3.json()['msg'] == '删除成功'
    @allure.story("删除用户分组")
    def test_deluser(self):
        pass

    # def test_CATEGORY(self):
    #     response1 = requests.post()
# 2、配置ini文件
# 3、练习数据驱动和rerun、makr一些内置方法